<?php

namespace Home\Controller;

use Home\Core\CommandSDK;

class IndexController extends BaseController
{
    /**
     * 获取下级结构信息列表
     */
    public function index()
    {
        // 获取登录用户的管理员角色
        $cookie = base64_decode($_COOKIE['user_info']);
        parse_str($cookie,$userinfo);
        if($userinfo['userrole'] == '0'){
            $url = 'Client/client';
        }
        if($userinfo['userrole'] == '1'){
            $url = 'account_overview/account_overview';
        }
        if($userinfo['userrole'] == '2'){
            // 获取区域id，设置session
            $areaid = $_GET['areaid'];
            $areaname = $_GET['areaname'];
            if(!$areaid){   // 初始化
                $area = $this->get_area();
                $areaid = $area['id'];
                $areaname = $area['name'];
            }
            session('AreaId',$areaid);
            session('AreaName',$areaname);
            $url = 'account_overview/account_overview';
        }
        $this->redirect($url);
    }

    /**
     * 获取区域列表
     */
    protected function get_area()
    {
        $param['pageid']=1;
        $param['pagecount']=10;
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::getAreaLists, $param, 'GET');
        $array1 = json_decode(json_encode($return), true);
        return $array1['areas'][0];
    }
   
    
}